/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package nickssnmp;

import javax.persistence.Query;
import javax.swing.JFrame;
import javax.swing.table.TableModel;

/**
 *
 * @author Nikolaos
 */
public class Report1_1 extends javax.swing.JPanel {
   
    SnmpUtil snmpUtil = null;    
    private JFrame parentFrame;
    /**
     * Creates new form Report1
     */
    public Report1_1() {
        initComponents();        
    }

    public Report1_1(JFrame parentFrame, SnmpUtil snmpUtil) {
        this.parentFrame = parentFrame;
        this.snmpUtil = snmpUtil;        
        initComponents();          
        
        report();        
        
        tblIfTable.setModel(getTableModel());
    }
    
    private void report(){
        
        String result = null;
        
        snmpUtil.setTargetVersion(1);
                 
        Query query = em.createNamedQuery("Oid.findByOidName");
        query.setParameter("oidName","sysDescr");                              
        result = snmpUtil.snmpGet(((Model.Oid) query.getResultList().get(0) ).getOidIndex()+ ".0");
        txtDescr.setText(result);

        query.setParameter("oidName","sysName");                              
        result = snmpUtil.snmpGet( ((Model.Oid) query.getResultList().get(0) ).getOidIndex() + ".0");
        txtName.setText(result);

        query.setParameter("oidName","sysLocation");                              
        result = snmpUtil.snmpGet( ((Model.Oid) query.getResultList().get(0) ).getOidIndex() + ".0");
        txtLocation.setText(result);

        query.setParameter("oidName","sysContact");                              
        result = snmpUtil.snmpGet( ((Model.Oid) query.getResultList().get(0) ).getOidIndex() + ".0");
        txtContact.setText(result);

        query.setParameter("oidName","ifNumber");                              
        result = snmpUtil.snmpGet( ((Model.Oid) query.getResultList().get(0) ).getOidIndex() + ".0");
        txtIfNumber.setText(result);

        query = em.createNamedQuery("Oid.findByOidName");
        query.setParameter("oidName","ifTable");

        String[] arr = new String[22];
        for(int i = 1; i<23 ; i++)
        {
            arr[i-1] = "1.3.6.1.2.1.2.2.1."+i;
        }                                   
        snmpUtil.insertIfTableRFC1213IntoDB(em,snmpUtil.snmpGetTable(arr));
	
//        query = em.createNativeQuery("Select * from data");
//        List<IfTableRfc1213> results = query.getResultList();
//        tblIfTable.
//        while (rs.next()) {
//        Vector row = new Vector(columns);
//        for (int i = 1; i <= columns; i++){
//        row.addElement( rs.getObject(i) );
//        }
//        data.addElement( row );
//        }
//        rs.close();
//        stmt.close();
        
    }
    private TableModel getTableModel() {        
        return new Table_1_1_Model(em);
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        em = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("NicksSNMPPU").createEntityManager();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblIfTable = new javax.swing.JTable();
        txtIfNumber = new javax.swing.JTextField();
        txtContact = new javax.swing.JTextField();
        txtLocation = new javax.swing.JTextField();
        txtName = new javax.swing.JTextField();
        txtDescr = new javax.swing.JTextField();

        jLabel2.setText("1. System Description");

        jLabel3.setText("2. System Name");

        jLabel1.setText("System Location");

        jLabel5.setText("3. System Contact");

        jLabel6.setText("4. Number of Interfaces");

        tblIfTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Description", "Type", "Mtu", "Speed"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(tblIfTable);

        txtIfNumber.setText("jTextField1");

        txtContact.setText("jTextField2");

        txtLocation.setText("jTextField4");

        txtName.setText("jTextField5");

        txtDescr.setText("jTextField6");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 674, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel5)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(jLabel1)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtIfNumber)
                            .addComponent(txtContact)
                            .addComponent(txtLocation)
                            .addComponent(txtName)
                            .addComponent(txtDescr))))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtDescr, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtLocation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txtContact, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(txtIfNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 291, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Ερώτημα 1ο", jPanel1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 471, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.persistence.EntityManager em;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable tblIfTable;
    private javax.swing.JTextField txtContact;
    private javax.swing.JTextField txtDescr;
    private javax.swing.JTextField txtIfNumber;
    private javax.swing.JTextField txtLocation;
    private javax.swing.JTextField txtName;
    // End of variables declaration//GEN-END:variables
}
